﻿using System;
using Web_Oto.Business;

namespace Administration
{
    public partial class Introduction : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var business = new IntroductionBus();
                var introduction = business.GetIntroduction();

                txtIntroduction.Text = string.Empty;
                if (introduction != null)
                    txtIntroduction.Text = introduction.Description;

                txtIntroduction.Language = "vi";
                var fileBrowser = new CKFinder.FileBrowser {BasePath = "/ckfinder/"};
                fileBrowser.SetupCKEditor(txtIntroduction);

            }

            msgBox.InnerHtml = string.Empty;
            msgBox.Attributes["class"] = "none;";
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtIntroduction.Text))
            {
                msgBox.InnerHtml = "<p><strong>Vui lòng nhập giới thiệu</strong></p>";
                msgBox.Attributes["class"] = "msg msg-error";

                return;
            }

            var business = new IntroductionBus();
            var result = business.Save(txtIntroduction.Text);
            if (result > 0)
            {
                msgBox.InnerHtml = "<p><strong>Lưu thành công</strong></p>";
                msgBox.Attributes["class"] = "msg msg-ok";
            }
            else
            {
                msgBox.InnerHtml = "<p><strong>Lưu không thành công</strong></p>";
                msgBox.Attributes["class"] = "msg msg-error";
            }
        }
    }
}